package org.bigdata.component;

import org.bigdata.service.HiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class HiveInitializer implements CommandLineRunner {

    @Autowired
    private HiveService hiveService;

    @Override
    public void run(String... args) throws Exception {
        String createTable = "CREATE TABLE IF NOT EXISTS user_data ("
                + "userId STRING, userName STRING, sex STRING) "
                + "ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' "
                + "STORED AS TEXTFILE";
        hiveService.query(createTable);

        String loadData = "LOAD DATA INPATH '/user/hadoop/input/user.csv' INTO TABLE user_data";
        hiveService.query(loadData);
    }
}

